// "pkg-exms/lib/pkg-exms.common.js"
import {CurdHelper, FormHelper} from "@/main";
import {CommonCurdDialgMixin} from "@/zpkgs/components/z-datatable/CurdDialgMixin";

// let EditCom = CurdHelper.defineEditCom('EditCom', {
//   properties: {
//     sourceDbName: {
//       ...FormHelper.FormInput('源数据库名', {
//       }),
//       rules: [],
//     },
//   }
// })

let defineDialogView = function (name, {content, mixinOption} = {}) {
  let template = `
    <div class="zcrud-dialog-view" :class="id">
  ${content}
  
<!--  <div class="zcrud-dialog-view__footer">-->
<!--<z-space>-->
<!--<el-button  type="primary"  -->
<!--@click="private__sendConfirm">提交</el-button>-->
<!--<el-button @click="private__sendCancel">取消</el-button>-->

<!--</z-space> -->
<!--</div>-->
    </div>
  `

  let ret = {
    name,
    template,
    mixins: [
      CommonCurdDialgMixin
    ],
    data() {
      let self = this;
      let id = ZY.rid();
      // console.log(properties)

      return {
        id,
      }
    },
    methods: {
      sendConfirm(ret) {
        this.$emit('confirm', ret)
      },
      sendCancel() {
        this.$emit('cancel', {
        })
      }
    }
  }

  return ret
}

let EditCom = CurdHelper.defineDialogView('EditCom2222', {
  content: `<div>111111111</div>`
})

let DetailCom =CurdHelper.defineDetailCom('DetailCom', {
  cls: 'detail-com-custom'
})

export function formatter(row, column, cellValue, index, { from } = {}) {
  let h = vueCompositionAPI.h
  return (<div><el-link>{cellValue}</el-link></div>);
}

export let obj = {
  defaultUrl: '/api/list',
  request: globalThis.Req,
  treeOption: {
    url: '/zy-boot/project/listProject?page=1&limit=99999'
  },
  viewProps: {
    iconOptions: [
      {
        icon: 'el-icon-info',
        tooltip: '详情1'
      },
    ]
  },
  events: {
    triggerIcons(...args) {
      console.log('triggerIcons', ...args)
    },
    triggerStatus(...args) {
      console.log('triggerStatus', ...args)
    },
  },
  columnDefMap: {
    sourceTable: {
      quick: true,
    },
    sourceDbName: {
      formatter,
    },
    prop11: {
      search: {
        type: 'string',
        ui: {
          label: '测试',
          widget: 'CusSelect',
          widgetConfig: {
            options: [
              {
                label: '1',
                value: '1'
              },
              {
                label: '2',
                value: '2'
              }
            ]
          }
        }
      }
    }
  },
  // dialog 属性
  dialogProps: {
    class: 'cus-dialog-cls'
  },
  EditCom,
  DetailCom,
}

export function onCurdInit(ctx) {
  console.log(obj)
}

export async function onCurdDelete(ctx) {
  // console.log('onCurdDelete', ctx)
  await ctx.refs.searchTable.search()
  await ZY.sleep(10000)
}
